package com.huajin.codetest.algorithm;

public class Test1 {

    public static void main(String[] args) {
        System.out.println(addDigits1(0));
        System.out.println(addDigits1(38));
        System.out.println(addDigits1(675));
    }

    public static int addDigits1(int num) {
        if (num == 0) {
            return 0;
        }
        if (num % 9 == 0) {
            return 9;
        }
        return num % 9;
    }

    public static int addDigits(int num) {
        if (num >= 0 && num <= 9) {
            return num;
        }
        String[] array = (num + "").split("");
        int length = array.length;
        int result = Integer.parseInt(array[0]);
        for (int i = 1; i < length; i++) {
            result += Integer.parseInt(array[i]);
        }
        return addDigits(result);
    }

    public static int singleNumber(int[] nums) {
        for (int i = 0; i < nums.length; i++) {

        }
        return 0;
    }

}
